package binarySystem;

/**
 * 功能描述:位计算器
 * 2025/04/18
 *
 * @author ZhangYi
 */
public class BitCalculator {


	public static  void printBit32(int num) {
		for (int i = 31; i >= 0; i--) {
			System.out.print((num & (1 << i)) == 0 ? "0" : "1");
		}
		System.out.println("");

	}


	public static void printBit64(long num){
		for (int i = 63;i>=0;i--){
			System.out.print((num & (1L << i)) == 0 ? "0" : "1");
		}
		System.out.println("");
	}

	public static void main(String[] args){
		System.out.println("32位的二进制数表示");
		int value1 = 3;
		int value2 = Integer.MAX_VALUE;
		System.out.print("value1 : ");
		printBit32(value1);
		System.out.print("value2 : ");
		printBit32(value2);

		System.out.print("value1 & value2 : ");
		printBit32(value1 & value2);
		System.out.print("value1 | value2 : ");
		printBit32(value1 | value2);
		System.out.print("value1 ^ value2 : ");
		printBit32(value1 ^ value2);
		System.out.print("~value1 : ");
		printBit32(~value1);
		System.out.print("~value2 : ");
		printBit32(~value2);

		System.out.println("64位的二进制数表示");
		printBit64(3L);
		printBit64(Integer.MAX_VALUE+0L);
	}
}
